run<template slot-scope="scope">
  <div class="user-manager-container">
    <el-row>
      <el-col :span="24">
        <el-card shadow="hover" class="header-card">
          <div slot="header" class="card-header">
            <span class="page-title">用户信息管理列表</span>
          </div>
          <el-form :inline="true" :model="searchForm">
            <el-form-item label="账号">
              <el-input
                v-model="searchForm.account"
                placeholder="请输入账号"
                prefix-icon="el-icon-search"
                clearable
              ></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="doSearch()">搜索</el-button>
              <el-button type="success" icon="el-icon-plus" @click="handleAdd()">新增</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </el-col>
    </el-row>
    <el-row class="mt-20">
      <el-col :span="24">
        <el-card shadow="hover">
          <el-table
            :data="pageData.list"
            border
            stripe
            highlight-current-row
            @selection-change="handleSelectionChange"
            class="user-table"
          >
            <el-table-column
              prop="id"
              label="ID"
              width="60"
            ></el-table-column>
            <el-table-column
              prop="account"
              label="账号"
              width="100"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="realName"
              label="真实姓名"
              width="100"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column label="性别" width="80">
              <template slot-scope="scope">
                <el-tag size="small" :type="scope.row.sex === 1 ? 'primary' : 'success'">
                  <span v-if="scope.row.sex === 1">男</span>
                  <span v-if="scope.row.sex === 2">女</span>
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column
              prop="birthday"
              label="生日"
              width="120"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="phone"
              label="手机号"
              width="120"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column
              prop="address"
              label="地址"
              width="240"
              :show-overflow-tooltip="true"
            ></el-table-column>
            <el-table-column label="操作" width="200" fixed="right">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="primary"
                  icon="el-icon-edit"
                  circle
                  @click="handleEdit(scope.$index, scope.row)"
                  title="修改"
                ></el-button>
                <el-button
                  size="mini"
                  type="danger"
                  icon="el-icon-delete"
                  circle
                  @click="handleDelete(scope.$index, scope.row)"
                  title="删除"
                ></el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            class="mt-20"
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="pageData.pageNo"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="pageData.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageData.totalCount"
          >
          </el-pagination>
        </el-card>
      </el-col>
    </el-row>
    <el-dialog
      :title="(saveForm.id == '' ? '新增' : '修改') + '用户信息'"
      :visible.sync="saveDialogVisible"
      width="50%"
      center
      :close-on-click-modal="false"
    >
      <el-form :model="saveForm" :rules="rules" ref="saveForm" label-position="right" label-width="120px" class="form-container">
        <el-form-item label="ID" label-width="120px" v-show="false">
          <el-input
            type="hidden"
            v-model="saveForm.id"
            autocomplete="off"
          ></el-input>
        </el-form-item>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="账号" label-width="120px" prop="">
              <el-input v-model="saveForm.account" autocomplete="off" placeholder="请输入账号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="姓名" label-width="120px" prop="">
              <el-input v-model="saveForm.realName" autocomplete="off" placeholder="请输入姓名"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="密码" label-width="120px" prop="">
              <el-input v-model="saveForm.password" autocomplete="off" placeholder="请输入密码" show-password></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" label-width="120px" prop="">
              <el-select v-model="saveForm.sex" placeholder="请选择性别" style="width: 100%">
                <el-option label="男" :value="1"></el-option>
                <el-option label="女" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="手机号" label-width="120px" prop="">
              <el-input v-model="saveForm.phone" autocomplete="off" placeholder="请输入手机号"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="生日" label-width="120px" prop="">
              <el-date-picker
                type="date"
                placeholder="选择日期"
                v-model="saveForm.birthday"
                value-format="yyyy-MM-dd"
                style="width: 100%"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="地址" label-width="120px" prop="">
          <el-input v-model="saveForm.address" autocomplete="off" placeholder="请输入地址"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="saveDialogVisible = false" icon="el-icon-close">取 消</el-button>
        <el-button type="primary" @click="doSave('saveForm')" icon="el-icon-check">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import qs from "qs";
export default {
  data() {
    return {
      rules: {
      },
      searchForm: {
        account: "",
        pageSize: 2,
        pageNo: 1,
      },
      pageData: {
        list: [],
        pageNo: 1,
        pageSize: 5,
        totalCount: 0,
        totalPageCount: 1,
      },
      saveDialogVisible: false,
      saveForm: {
        id: "",
        account: "",
        password: "",
        realName: "",
        sex: "",
        birthday: "",
        phone: "",
        roleId: ""
      },
    };
  },
  mounted() {
    this.doSearch();
  },
  methods: {
    logout() {
      this.$store.commit("logout");
      this.$message.success("注销成功");
      this.$router.push({ path: "/" });
    },
    handleDelete(index, row) {
      this.$confirm("此操作将永久删除该记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$axios.get("/user/delete?id=" + row.id).then((response) => {
            this.$message.success("删除成功");
            this.doSearch();
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    handleEdit(index, row) {
      this.saveDialogVisible = true;
      this.$axios.post("/user/selectByIdUser?id=" + row.id).then((response) => {
        this.saveForm = response.data;
        this.saveDialogVisible = true;
      });
    },
    doSave(saveForm) {
      let queryStr = qs.parse(qs.stringify(this.saveForm));
      if (this.saveForm.id == "" || this.saveForm.id == null) {
        this.$axios.post("/user/insert", queryStr).then((response) => {
          this.saveDialogVisible = false;
          this.$message.success("添加成功");
          this.doSearch();
        });
      } else {
        this.$axios.post("/user/update", queryStr).then((response) => {
          this.saveDialogVisible = false;
          this.$message.success("修改成功");
          this.doSearch();
        });
      }
    },
    handleAdd() {
      this.saveForm = {
        id: "",
        account: "",
        password: "",
        realName: "",
        sex: "",
        birthday: "",
        phone: "",
        address: "",
        roleId: "",
      };
      this.saveDialogVisible = true;
    },
    doSearch() {
      let bodyData = qs.stringify(this.searchForm);
      this.$axios.post("/user/page", bodyData).then((response) => {
        this.pageData = response.data;
      });
    },

    handleSelectionChange(val) {
      console.log(val);
    },
    handleSizeChange(pageSize) {
      this.searchForm.pageSize = pageSize;
      this.doSearch();
    },
    handleCurrentChange(pageNo) {
      this.searchForm.pageNo = pageNo;
      this.doSearch();
    },
  },
};
</script>
<style>
.user-manager-container {
  padding: 15px;
}

.mt-10 {
  margin-top: 10px;
}

.mt-20 {
  margin-top: 20px;
}

.my-msg {
  margin-top: -30px;
  margin-right: 20px;
}

.page-title {
  font-size: 18px;
  font-weight: bold;
  color: #303133;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-card {
  border-left: 4px solid #409EFF;
}

.user-table {
  margin-top: 10px;
}

.form-container {
  padding: 10px 20px;
}

.el-form-item__label {
  font-weight: 500;
}

.dialog-footer {
  text-align: center;
  margin-top: 10px;
}
</style>